<%- include('css') %>
<link rel="stylesheet" href="/public/js_module/simditor/css/simditor.css">
<div id="app" style="width:980px">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>中心员工信息</legend>
    </fieldset>

    <form class="layui-form layui-form-pane" action="" lay-filter="form">

        <div class="layui-form-item">
            <label class="layui-form-label">登录账号</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" placeholder="请输入登录账号" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="required" placeholder="请输入登录密码" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">员工姓名</label>
            <div class="layui-input-block">
                <input type="text" name="realname" lay-verify="required|realname" placeholder="请输入员工姓名" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" maxlength="11" name="phone" lay-verify="required|phone" placeholder="请输入手机号" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="textarea" name="remark" lay-verify="required" placeholder="备注"  autocomplete="off" class="layui-input" disabled></input>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所属中心</label>
            <div class="layui-input-block">
                <select name="belong_id" lay-verify="required" lay-search="" lay-filter="center" id="center_id" disabled>
                    <option value="" >直接选择或搜索选择</option> <!-- v-if="item.id == "-->
                    <option :value="item.id" v-for="(item,index) in centers" :key="index">{{item.name}}</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" v-on:click="doclose" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</div>

<%- include('script') %>
<script>
    var vm = new Vue({
        el: '#app',
        data:function(){

            return {
                isButtonDisabled:false,
                load:false,
                centers:[],
                id:'<%=id%>'
            }

        },
        mounted:function(){

            var self = this;

            layui.use(['form'], function () {
                var form = layui.form;

                var l = layer.load();

                self.getcenters(l)

                $.ajax({
                    url:'/admin/centeruser/'+self.id,
                    type:'GET',
                    data:{},
                    success:(res)=>{
                        if(res.code === 200){
                            let inter = setInterval(()=>{
                                if(self.load){
                                    form.val("form",res.data);
                                    form.render('select');
                                    clearInterval(inter);
                                    layer.close(l);
                                }
                            },1000)
                        }else{
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.layer.msg('获取数据失败：'+res.error+' -- '+res.code,{icon:2});
                        }
                    },
                    fail:()=>{
                        layer.close(l);
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        parent.layer.msg('请求获取数据失败',{icon:2});
                    }
                });

            });
        },

        methods:{

            doclose:function(){
                parent.vm.iframeclose();
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            },
            getcenters:function(load,v){
                let self = this;
                $.ajax({
                    url:'/admin/center',
                    type:'GET',
                    data:{isPage:false},
                    success:(res)=>{
                        if(res.code == 0){
                            self.centers = res.data;
                            self.load = true;
                        }else{
                            layer.close(load);
                            layer.msg('获取中心数据失败：'+res.error+' -- '+res.code,{icon:2})
                        }
                    },
                    fail:(res)=>{
                        clearInterval(v);
                        layer.close(load);
                        layer.msg('获取中心数据失败!  原因：请求发起失败',{icon:2})
                    }
                });
            }
        }
    })
</script>
